// pages/new/new.js
import {addPhoneBook} from '../util/request.js'
import Toast from '@vant/weapp/toast/toast'
Page({
  data: {
    name:'',
    phone:'',
    active:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  async onSubmit(){
    await addPhoneBook(this.data) 
    this.setData({
      phone:'',
      name:''
    })
    Toast('添加成功');
  
  },
  onChange(event) {
    // event.detail 的值为当前选中项的索引
    if(this.data.active==event.detail)
      return
    if(event.detail==0){
      wx.navigateTo({
        url: '../index/index',
      })
    }else if(event.detail==1){
      wx.navigateTo({
        url: '../new/new',
      })
    }else{
      wx.navigateTo({
        url: '../initGroup/initGroup',
      })
    }
  }
})